import java.io.FileReader;
import java.io.FileWriter;
import java.util.Properties;
import java.util.Set;

/**
 * @author zhangyan
 * @date 2020/5/20 19:45
 */
public class Test19 {
    public static void main(String[] args) throws Exception{

        //创建Properties对象
        Properties pro = new Properties();

        //调用load方法 关联流对象
        FileReader fr = new FileReader("Demo02\\Student.txt");
        pro.load(fr);

        //获取pro所有键
        Set<String> keySet = pro.stringPropertyNames();

        //遍历set集合
        for (String key : keySet) {
            //判断是否包含刘方
            if (key.equals("刘方")){
                //如果有,存入新的值
                pro.setProperty("刘方","18");
            }
        }
        fr.close();

        //新数据写入到newstu.txt文件中

        FileWriter fw = new FileWriter("Demo02\\newstu.txt");
        pro.store(fw,"");
    }
}
